#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, mod;
int tr[N << 2];
void build(int p, int l, int r) {
  tr[p] = 1;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
}
void update(int pos, int val, int p, int l, int r) {
  if (l == r) {
    tr[p] = val % mod;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(pos, val, p << 1, l, mid);
  else
    update(pos, val, p << 1 | 1, mid + 1, r);
  tr[p] = 1ll * tr[p << 1] * tr[p << 1 | 1] % mod;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> mod;
    build(1, 1, n);
    rep(i, 1, n) {
      int op, x;
      cin >> op >> x;
      if (op == 1)
        update(i, x, 1, 1, n);
      else
        update(x, 1, 1, 1, n);
      cout << tr[1] << endl;
    }
  }
  return 0;
}